/**
 * 设置Json属性
 * @param {Object} orginJson 
 * @param {{Object} targetJson 
 */
function setJsonProps(orginJson, targetJson) {
  for (let key in targetJson) {
    orginJson[key] = targetJson[key];
  }
}

/**
 * px转rpx
 * @param {Number} px 
 */
function pxToRpx(px) {
  return px * 750 / getApp().globalData.winWidth;
}

/**
 * rpx转px
 * @param {Number} rpx 
 */
function rpxToPx(rpx) {
  return rpx / 750 * getApp().globalData.winWidth;
}

/**
 * 获固定在顶部的搜索框宽度
 */
function getFixedSearchWidth() {
  const globalData = getApp().globalData;
  const spacing = rpxToPx(30);
  const winWidth = globalData.winWidth;
  const capWidth = globalData.capWidth;
  const capRight = globalData.capRight;
  return winWidth - capWidth - (spacing * 3) - capRight;
}

/**
 * 获取导航栏滚动高度
 * @param {Number} scrollTop 
 */
function getNavScrollTop(scrollTop) {
  const navHeight = getApp().globalData.navHeight;
  return scrollTop + navHeight;
}

module.exports = {
  setJsonProps,
  pxToRpx,
  rpxToPx,
  getFixedSearchWidth,
  getNavScrollTop
}